package com.shoulder.imports;

import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.util.Collection;

import static java.nio.charset.StandardCharsets.UTF_8;

public class ImportsFiles {
    public static final String META_INF_PATH = "META-INF";
    public static final String SPRING_META_INF_PATH = META_INF_PATH + "/spring/";
    public static final String IMPORTS_FILE_NAME = "org.springframework.boot.autoconfigure.AutoConfiguration.imports";
    public static final String SPRING_IMPORTS_FILE_PATH = SPRING_META_INF_PATH + IMPORTS_FILE_NAME;
    public static final String ANNOTATION_NAME = "org.springframework.boot.autoconfigure.AutoConfiguration";

    /**
     * Writes the set of service class names to a service file.
     *
     * @param output   not {@code null}. Not closed after use.
     * @param services a not {@code null Collection} of service class names.
     */
    static void writeImportFile(Collection<String> services, OutputStream output)
            throws IOException {
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(output, UTF_8));
        for (String service : services) {
            writer.write(service);
            writer.newLine();
        }
        writer.flush();
    }
}
